<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
// @codingStandardsIgnoreFile
?>
<?php
/**
 * @var $block \Magento\Reports\Block\Product\Viewed
 */
?>
<?php
if ($exist = ($block->getRecentlyViewedProducts() && $block->getRecentlyViewedProducts()->getSize())) {
    $type = 'widget-viewed';
    $mode = 'list';

    $type = $type . '-' . $mode;

    $image = 'recently_viewed_products_images_names_widget';
    $title = __('Recently Viewed');
    $items = $block->getRecentlyViewedProducts();

    $showWishlist = false;
    $showCompare = false;
    $showCart = false;
    $rating = false;
    $description = false;
}
?>
<?php if ($exist): ?>
    <div class="block-title-main">
        <h2><?php /* @escapeNotVerified */ echo $title; ?></h2>
        <div class="title-border"></div>
    </div>
    <div style="margin-bottom: 0;float: left;width:100%;" class="pad-main-bottom block widget block-viewed-products-<?php /* @escapeNotVerified */ echo $mode; ?>">
        <div class="block-content">
            <?php $suffix = $block->getNameInLayout(); ?>
            <ol style="margin: 30px 0 0;" class="product-slider product-items" id="widget-viewed-<?php /* @escapeNotVerified */ echo $suffix; ?>">
                <?php $iterator = 1; ?>
                <?php foreach ($items as $_product): ?>
                    <?php /* @escapeNotVerified */ echo($iterator++ == 1) ? '<li class="product-item">' : '</li><li class="product-item">' ?>
                    <div class="product-item-info">
                        <a class="product-item-photo" href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>"
                           title="<?php /* @escapeNotVerified */ echo $block->stripTags($_product->getName(), null, true) ?>">
                               <?php echo $block->getImage($_product, $image)->toHtml(); ?>
                        </a>
                        <div class="product-item-details">
                            <strong class="product-item-name">
                                <a href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>"
                                   title="<?php /* @escapeNotVerified */ echo $block->stripTags($_product->getName(), null, true) ?>"
                                   class="product-item-link">
                                       <?php /* @escapeNotVerified */ echo $this->helper('Magento\Catalog\Helper\Output')->productAttribute($_product, $_product->getName(), 'name') ?>
                                </a>
                            </strong>
                            <?php
                            /* @escapeNotVerified */ echo $block->getProductPriceHtml(
                                    $_product, \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE, \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST, [
                                'price_id_suffix' => '-widget-viewed-' . $suffix
                                    ]
                            )
                            ?>
                            <div class="product-item-actions">
                                <?php if ($_product->isSaleable()): ?>
                                    <div class="actions-primary">
                                        <?php if ($_product->getTypeInstance()->hasRequiredOptions($_product)): ?>
                                            <button class="action tocart primary"
                                                    data-mage-init='{"redirectUrl": {"url": "<?php /* @escapeNotVerified */ echo $block->getAddToCartUrl($_product) ?>"}}'
                                                    type="button" title="<?php /* @escapeNotVerified */ echo __('Add to Cart') ?>">
                                                <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
                                            </button>
                                        <?php else: ?>
                                            <?php
                                            $postDataHelper = $this->helper('Magento\Framework\Data\Helper\PostHelper');
                                            $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_product), ['product' => $_product->getEntityId()]);
                                            ?>
                                            <button type="button" class="action tocart primary" data-post='<?php /* @escapeNotVerified */ echo $postData; ?>'>
                                                <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
                                            </button>
                                        <?php endif; ?>
                                    </div>
                                <?php else: ?>
                                    <?php if ($_product->getIsSalable()): ?>
                                        <div class="stock available"><span><?php /* @escapeNotVerified */ echo __('In stock') ?></span></div>
                                    <?php else: ?>
                                        <div class="stock unavailable"><span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span></div>
                                            <?php endif; ?>
                                        <?php endif; ?>
                            </div>
                        </div>
                    </div>
                    <?php echo($iterator == count($items) + 1) ? '</li>' : '' ?>
                <?php endforeach; ?>
            </ol>
        </div>
    </div>
    <script>
        require(['jquery', 'cpowlcarousel'], function ($) {
            $(document).ready(function () {
                $(".product-slider").owlCarousel({
                    items: 5,
                    itemsDesktop: [1080, 4],
                    itemsDesktopSmall: [860, 3],
                    itemsTablet: [768, 3],
                    itemsTabletSmall: [639, 2],
                    itemsMobile: [360, 2],
                    pagination: false,
                    navigationText: ["<div class='lft-btn'><i class='fa fa-angle-left'></i></div>", "<div class='rgt-btn'><i class='fa fa-angle-right'></div>"],
                    navigation: true,
                });
            });
        });
    </script>
<?php endif; ?>
